{include 'admin/layout/header_list'}
<link rel="stylesheet" href="__ADMIN_STATIC__/css/addContent.css">
<div class="addcontent" >
    <form class="ajaxForm" method="post">
        <input type="hidden" name="_method" value="post">
        <table class="table" >
            <tr>
                <td class="tl">
                    <span><strong>* </strong>所属导航</span>
                </td>
                <td>
                    <select class="short" name="nav_id" >
                        <option>请选择</option>
                        {YiFang:YifangBackendAccount_rbacNav_selectHtml /}
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <span><strong>* </strong>名称</span>
                </td>
                <td>
                    <input class="long" type="text" name="name" value="">
                </td>
            </tr>
            <tr>
                <td>
                    <span><strong>* </strong>路由</span>
                </td>
                <td>
                    <input class="long" type="text" name="route" value="">
                </td>
            </tr>
            <tr>
                <td>
                    <span><strong>* </strong>排序</span>
                </td>
                <td>
                    <input class="long" type="text" name="sort" value="99">
                </td>
            </tr>
            <tr>
                <td>
                    <span><strong>* </strong>显示</span>
                </td>
                <td>
                    <p class="article-status">
                        <input name="is_show" type="radio" value="1" checked >是
                        <input name="is_show" type="radio" value="0" >否
                    </p>
                </td>
            </tr>
            <tr>
                <td>
                    <span><strong>* </strong>插件目录</span>
                </td>
                <td>
                    <input class="long" type="text" name="plugins" value="">
                </td>
            </tr>
            <tr>
                <td>
                    <span><strong>* </strong>功能名称</span>
                </td>
                <td>
                    <input class="long" type="text" name="right_index" value="">
                </td>
            </tr>
            <tr>
                <td>
                    <span><strong></strong>权限码集合</span>
                </td>
                <td>
                    <div>
                        <table class="table right_table" >
                            <tr>
                                <td style="width:750px;" >权限码</td>
                                <td style="width:100px;">操作</td>
                            </tr>
                        </table>
                        <div style="margin-top:10px;" >
                            <button class="submit" type="button" onclick="create_right()" >添加</button>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>添加权限码：</td>
                <td>
                    <div>
                        <select style="width:350px;display: inline-block;" id="controller" onchange="get_list_action(this.value);"><option value='' selected=selected>请选择</option></select>
                        <span style="display: inline-block;" >@</span>
                        <select style="width:200px;display: inline-block;" id='action'></select>
                        <button style="display: inline-block;" type="button" class="btn" onclick='create_right_auto();'><span class="add">添 加</span></button>
                    </div>
                </td>
            </tr>
        </table>
    </form>
    <div class="yifang-button">
        <button class="submit ajaxBtn" data-submit-url="{YIFANG_ROUTE_PREFIX}/yifang_backend_account/rbacNode" data-form=".ajaxForm" data-close="5">
            提交
        </button>
        <button class="cancel">取消并返回</button>
    </div>
</div>
<script>
    //动态获取动作列表
    function get_list_action(controller_path)
    {
        $('#action').empty();
        $.getJSON('{YIFANG_ROUTE_PREFIX}/yifang_backend_account/permissionCode/action',{controller:controller_path},function(content){
            if(content.success){
                var data=content['data']["action"];
                for(d_index in data)
                {
                    var optionStr = '<option value="'+data[d_index]["name"]+'">'+data[d_index]["name"]+'</option>';
                    $('#action').append(optionStr);
                }
            }
        });
    }

    $(function(){
        //动态获取控制器文件列表
        $.getJSON('{YIFANG_ROUTE_PREFIX}/yifang_backend_account/permissionCode/controller',function(content){
            if(content.success){
                var data=content['data']["controller"];
                for(d_index in data)
                {
                    var optionStr = '<option value="'+data[d_index]["path"]+'">'+data[d_index]["name"]+'</option>';
                    $('#controller').append(optionStr);
                }
            }
            if($('#controller').val()){
                get_list_action($('#controller').val());
            }else{
                $('#action').empty();
            }
        });
    });

    //添加权限码
    function create_right(val){
        var val = (val == undefined) ? '':val;
        var html='<tr>'
                +'<td class="tl">'
                +'<input style="width:850px;" type="text" placeholder="controller@method" name="right[]" value="'+val+'">'
                +'</td>'
                +'<td>'
                +'<span style="display:inline-block;padding:3px 6px;border:1px solid gray;cursor: pointer;" onclick="$(this).parent().parent().remove();" title="删除" >x</span>'
                +'</td>'
                +'</tr>';
        $(".right_table").append(html);
    }

    //自动添加权限码
    function create_right_auto()
    {
        var controllerVal   = $('#controller').val();
        var actionVal = $('#action').val();
        if(controllerVal && actionVal)
        {
            create_right(controllerVal+'@'+actionVal);
        }
        else
        {
            alert('控制器或者动作不能为空');
        }
    }
</script>
<script src="__ADMIN_STATIC__/js/addContent.js"></script>
{include 'admin/layout/footer'}